import 'package:flutter/material.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/apis/user.dart';

class MyWechat extends StatefulWidget {
  MyWechat({Key key}) : super(key: key);

  @override
  _MyWechatState createState() => _MyWechatState();
}

class _MyWechatState extends State<MyWechat> {
  final textCtrl = TextEditingController();

  @override
  void initState() {
    super.initState();

    UserApis.getWechat().then((wechat) {
      if (!mounted) return;
      textCtrl.text = wechat;
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('我的微信'),
        actions: [
          IconButton(
            onPressed: () {
              UserApis.setWechat(textCtrl.text).then((res) {
                toast('保存成功');
                Navigator.of(context).pop();
              });
            },
            icon: Text("保存"),
          ),
        ],
      ),
      body: Container(
        padding: EdgeInsets.symmetric(
          horizontal: px(30),
          vertical: px(50),
        ),
        child: TextField(
          controller: textCtrl,
          maxLength: 20,
          decoration: InputDecoration(
            labelText: '微信：',
          ),
        ),
      ),
    );
  }
}
